package com.dzjcloud.dzj.common.satoken;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * <h3>dzj-cloud</h3>
 * <p>[Sa-Token 权限认证] 配置类 </p>
 *
 * @author : DongZeJian
 * @date : 2021-05-26 16:27
 **/
@Configuration
@ConfigurationProperties(prefix = "app")
@Data
public class SaTokenConfigure implements WebMvcConfigurer {

    private List<String> release;

    // 注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册 Sa-Token 拦截器，校验规则为 StpUtil.checkLogin() 登录校验。
        registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
                .addPathPatterns("/**")
                .excludePathPatterns(release);
    }
}
